package main

import (
	"fmt"

	"gitee.com/go-course/go8/micro/rpc/protobuf/sample/pb"
	"google.golang.org/protobuf/types/known/anypb"
)

type Blog struct {
	Status pb.STATUS
}

func main() {
	b := Blog{}

	fmt.Println(b)

	// e := pb.Event{
	// 	Type: pb.TYPE_RESOURCE_ALERT,
	// 	Data: &pb.Event_ResourceChange{},
	// }

	// switch e.Type {
	// case pb.TYPE_RESOURCE_CHANGE:
	// 	e.GetResourceChange()
	// case pb.TYPE_RESOURCE_ALERT:
	// 	e.GetResourceAlert()
	// }

	// any的传参
	any, err := anypb.New(&pb.Blog{
		Title:  "test",
		Author: "old yu",
	})
	if err != nil {
		panic(err)
	}
	device := pb.Device{
		DeviceType: "a1",
		// 不能直接把对象传递进去
		Data: any,
	}
	fmt.Println(device)

	// 如何解析any
	blogA1 := &pb.Blog{}
	err = device.Data.UnmarshalTo(blogA1)
	if err != nil {
		panic(err)
	}
	fmt.Println(blogA1)
}
